package com.lld.im.common.router.algorithm.consistenthash;

import com.lld.im.common.enums.UserErrorCode;
import com.lld.im.common.exception.ApplicationException;
import com.lld.im.common.router.RouterHandler;

import java.util.List;

/**
 * 负载均衡-一致性哈希算法
 */
public class ConsistentHashRouterHandler implements RouterHandler {

    private ConsistentHashHandler handler=new ConsistentHashHandler();

    @Override
    public String getServer(List<String> severs, String id) {
        int size = severs.size();
        if(size==0){
            throw new ApplicationException(UserErrorCode.SERVER_NOT_AVAILABLE);
        }
        return handler.process(severs,id);
    }

}
